package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.hfq.UploadBaseData;
import com.ucredit.babel.common.model.hfq.gps.UploadGpsData;
import com.ucredit.babel.common.model.hfq.gps.UploadGpsRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Classname HfgGpsInfo
 * @Description GPS
 * @Date 2021/6/8 20:21
 * @Created by lzw
 */
public class HfgGpsInfo extends ParseBase {
    Text key = new Text();
    Text value = new Text();

    @Override
    public boolean parseJob(Mapper.Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        UploadGpsRecord obj = (UploadGpsRecord) model;
        UploadGpsData data = obj.getData();
        UploadBaseData baseData = data.getBaseData();

        StringBuilder sb = getBaseInfo(obj, successful);
        sb.append(baseData.getHttpTimestamp()).append(CRT001);
        sb.append(baseData.getUploadInfoOpportunity()).append(CRT001);
        sb.append(obj.getType()).append(CRT001);

        sb.append(data.getLongitude()).append(CRT001);
        sb.append(data.getLatitude()).append(CRT001);
        sb.append(data.getProvince()).append(CRT001);
        sb.append(data.getCity()).append(CRT001);
        sb.append(data.getAddress()).append(CRT001);
        sb.append(data.getAltitude()).append(CRT001);
        sb.append(formatValue(data.getOriginData())).append(CRT001);

        key.set(getKey());
        value.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, value);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_hfq_gps_inc";
    }

    @Override
    public String getType() {
        return RecordType.HFQ_UPLOAD_GPS_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "GPS";
    }
}
